package weaver.interfaces.jhthome.duss.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

public class WeaWlxjdzlcAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>>WeaWlxjdzlcAction>>>>>requestid=" + requestid);
        writeLog(">>>>>WeaWlxjdzlcAction>>>>>tablename=" + tablename);
        JhthomeUtil jhthomeUtil = new JhthomeUtil();
        try {
            int dataid = 0;
            BaseBean baseBean = new BaseBean();
            baseBean.writeLog(">>>>>getWlxjd.jsp>>>>>requestid=" + requestid);
            rs.executeQuery("select id,sqr,bm,sqrq,sfjsbj,gllc,bjcs from " + tablename + " where requestid='" + requestid + "'");
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String sqr = Util.null2String(rs.getString("sqr"));
            String bm = Util.null2String(rs.getString("bm"));
            String sqrq = Util.null2String(rs.getString("sqrq"));
            String sfjsbj = Util.null2String(rs.getString("sfjsbj"));
            String gllc = Util.null2String(rs.getString("gllc"));
            baseBean.writeLog(">>>>>WeaWlxjdzlcAction>>>>>mainid=" + mainid + ",sfjsbj=" + sfjsbj);
            if ("1".equals(sfjsbj)) {
                rs.execute("select * from " + tablename + "_dt1 where mainid='" + mainid + "'");
                while (rs.next()) {
                    Map<String, Object> dataMap = new HashMap<String, Object>();
                    dataMap.put("requestId", requestid);
                    dataMap.put("sqr", sqr);
                    dataMap.put("bm", bm);
                    dataMap.put("sqrq", sqrq);
                    int newbjsc = 1;
                    String bjsc = jhthomeUtil.getBjcs(requestid);
                    if (!"".equals(bjsc)) {
                        newbjsc = Util.getIntValue(bjsc) + 1;
                    }
                    dataMap.put("bjcs", newbjsc);
                    dataMap.put("bh", Util.null2String(rs.getString("bh")));
                    dataMap.put("wlmcxxgg", Util.null2String(rs.getString("wlmcxxgg")));
                    dataMap.put("bcsm", Util.null2String(rs.getString("bcsm")));
                    dataMap.put("sliang", Util.null2String(rs.getString("sliang")));
                    dataMap.put("dwmm", Util.null2String(rs.getString("dwmm")));
                    dataMap.put("djjmf", Util.null2String(rs.getString("djjmf")));
                    dataMap.put("pcbz", Util.null2String(rs.getString("pcbz")));
                    dataMap.put("jgydpl", Util.null2String(rs.getString("jgydpl")));
                    dataMap.put("sfecjg", Util.null2String(rs.getString("sfecjg")));
                    dataMap.put("yxq", Util.null2String(rs.getString("yxq")));
                    dataMap.put("zzcp", Util.null2String(rs.getString("zzcp")));
                    dataMap.put("kh", Util.null2String(rs.getString("kh")));
                    dataMap.put("sl", Util.null2String(rs.getString("sl")));
                    dataMap.put("ylzssm", Util.null2String(rs.getString("ylzssm")));
                    dataMap.put("qmqq", Util.null2String(rs.getString("qmqq")));
                    dataMap.put("ssl", Util.null2String(rs.getString("ssl")));
                    dataMap.put("bcsx", Util.null2String(rs.getString("bcsx")));
                    dataMap.put("fjsc", Util.null2String(rs.getString("fjsc")));
                    dataMap.put("bjr", Util.null2String(rs.getString("bjr")));
                    dataMap.put("sbje", Util.null2String(rs.getString("sbje")));
                    dataMap.put("zt", sfjsbj);
                    dataMap.put("gllc", gllc);
                    baseBean.writeLog(">>>>>getWlxjd.jsp>>>>>dataMap=" + dataMap);
                    dataid = jhthomeUtil.insertModelData(285, 1, dataMap);
                }
                rs.execute("update "+tablename+" set bjcs=bjcs+1 where requestid='"+requestid+"'");
            }else {
                rs.execute("update uf_wlxjdtz set zt='"+sfjsbj+"' where requestId='"+requestid+"'");
            }
            baseBean.writeLog(">>>>>WeaWlxjdzlcAction>>>>>dataid=" + dataid);
            if (dataid >= 0) {
                return Action.SUCCESS;
            } else {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent("Action Exception: insert fail");
                return Action.FAILURE_AND_CONTINUE;
            }

        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action Exception��");
            return Action.FAILURE_AND_CONTINUE;
        }

    }


}
